﻿using FlexPlatform.Contracts.DataModel.Identification;
using FlexPlatform.Contracts.DataModel;
using FlexPlatform.Contracts.Configuration;

namespace FlexPlatform.DataModel.DataAccess.Identification
{
    public class EntityIdentifierConfigurator<T> where T:IDbEntity
    {
        IIdentificationConfiguration<T> entityConfiguration;

        public EntityIdentifierConfigurator(IIdentificationConfiguration<T> configurationContainer)
        {
            this.entityConfiguration = configurationContainer;
        }

        public IIdentifyingFieldGroup<T> AddNewGroup(string groupName)
        {
            var newGroup = new IdentifyingFieldGroup<T>(entityConfiguration.IdentificationGroups.Count + 1);
            entityConfiguration.IdentificationGroups.Add(groupName, newGroup);

            return newGroup;
        }

        public IIdentifyingFieldGroup<T> GetGroup(string groupName)
        {
            IIdentifyingFieldGroup<T> goupToReturn = null;
            entityConfiguration.IdentificationGroups.TryGetValue(groupName, out goupToReturn);

            return goupToReturn;
        }
    }
}
